package com.session02.homework;

import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) {
        //判断用户输入的字符串是否是一个格式正确的IP地址；
        //IP地址是一个由4个数字用3个点分隔开的字符串，每个数字只能是0-255
        //比如：2.13.111.89
        //String str="([0-9]|1?[0-9]{2}|2[0-5]{2}).([0-9]|1?[0-9]{2}|2[0-5]{2}).([0-9]|1?[0-9]{2}|2[0-5]{2}).([0-9]|1?[0-9]{2}|2[0-5]{2})";
        //String str="(([0-9]|1?[0-9]{2}|2[0-5]{2}).){3}([0-9]|1?[0-9]{2}|2[0-5]{2})";
        String str="(([0-9]|1?[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|1?[0-9]{2}|2[0-4][0-9]|25[0-5])";
        System.out.println("请输入一个字符串：");
        Scanner input = new Scanner(System.in);
        String s = input.next();
        boolean flag=s.matches(str);
        if (flag){
            System.out.println("该字符串是一个格式正确的IP地址");
        }else {
            System.out.println("错误IP地址");
        }
    }
}
